package opdb

import (
	"database/sql/driver"
	"regexp"
	"unicode"
)

var (
	sqlRegexp                = regexp.MustCompile(`\?`)
	numericPlaceHolderRegexp = regexp.MustCompile(`\$\d+`)
)

func isPrintable(s string) bool {
	for _, r := range s {
		if !unicode.IsPrint(r) {
			return false
		}
	}
	return true
}

//Stmt ...
type Stmt struct {
	dc  *conn
	Num int
	SQL string
}

//Close ...
func (m *Stmt) Close() error {
	return nil
}

//NumInput ...
func (m *Stmt) NumInput() int {
	return m.Num
}

//Exec ...
func (m *Stmt) Exec(args []driver.Value) (driver.Result, error) {
	m.SQL = m.dc.parser(m.SQL, args)
	//log.Println("Exec:", m.SQL)
	return m.dc.Exec(m.SQL, nil)
}

//Query ...
func (m *Stmt) Query(args []driver.Value) (driver.Rows, error) {
	m.SQL = m.dc.parser(m.SQL, args)
	//log.Println("Query:", m.SQL)
	return m.dc.Query(m.SQL, nil)
}
